//
//  FileDetailController.m
//  FileSystemDemo
//
//  Created by 小草毋正 on 2018/1/9.
//  Copyright © 2018年 C-LOVE. All rights reserved.
//

#import "FileDetailController.h"
#import "TxtController.h"

@interface FileDetailController ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *sizeLabel;
@property (weak, nonatomic) IBOutlet UILabel *createTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *editTimeLabel;

@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
@property (weak, nonatomic) IBOutlet UIButton *moveButton;
@property (weak, nonatomic) IBOutlet UIButton *playButton;


@end

@implementation FileDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.file.name;
    self.nameLabel.text = self.file.name;
    self.createTimeLabel.text = [self stringForDate:self.file.fileInfo.creatDate];
    self.editTimeLabel.text = [self stringForDate:self.file.fileInfo.modificationDate];
    
    //KB  if(1000000)
    if(self.file.fileInfo.size < 1000){
        self.sizeLabel.text = [NSString stringWithFormat:@"%llu B", self.file.fileInfo.size];
    }
    else if(self.file.fileInfo.size < 1000000){
        self.sizeLabel.text = [NSString stringWithFormat:@"%.2lf KB", self.file.fileInfo.size * 0.001];
    }
    else if(self.file.fileInfo.size < 1000000000){
        self.sizeLabel.text = [NSString stringWithFormat:@"%.2lf M", self.file.fileInfo.size * 0.000001];
    }
    else {
        self.sizeLabel.text = [NSString stringWithFormat:@"%.2lf G", self.file.fileInfo.size * 0.000000001];
    }
}

- (IBAction)buttonAction:(UIButton *)sender {
    if(sender == self.deleteButton){
        if(self.oprationBlock){
            self.oprationBlock(OperationTypeDelete, self.file.filePath);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else if(sender == self.playButton){
        if(self.file.fileType == CLFileTypeLRC || self.file.fileType == CLFileTypeMD || self.file.fileType == CLFileTypeCode ){
            TxtController *controller = [[TxtController alloc] init];
            controller.file = self.file;
            [self.navigationController pushViewController:controller animated:YES];
        }
    }
    
   
}



- (NSString *)stringForDate:(NSDate *)date {
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:date];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end

